package edu.toronto.whimper.GraphsObjects;


import java.util.ArrayList;
import java.util.Observable;
import java.util.Observer;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

public class NoiseDataSource implements Runnable {

    // encapsulates management of the observers watching this datasource for update events:
    class MyObservable extends Observable {
    @Override
    public void notifyObservers() {
        setChanged();
        super.notifyObservers();
    }
}
    ArrayList <Number> xData;
    ArrayList <Number> yData;
    
    public NoiseDataSource(ArrayList <Number> xData, ArrayList <Number> yData){
    	this.xData = xData;
    	this.yData = yData;
    }
    
    private MyObservable notifier;

    {
        notifier = new MyObservable();
    }

    //@Override
    public void run() {
    	
        try {
            boolean isRising = true;
            while (true) {

                Thread.sleep(50); 
                // decrease or remove to speed up the refresh rate.
                notifier.notifyObservers(); 
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public int getItemCount(int series) {
        return xData.size();
    }

    
    public Number getX(int series, int index) {
    	return xData.get(index);
    }

    public Number getY(int series, int index) {
         return yData.get(index);
    }

    public void addObserver(Observer observer) {
        notifier.addObserver(observer);
    }

    public void removeObserver(Observer observer) {
        notifier.deleteObserver(observer);
    }

}
